#ifndef GTL_ENGINE_OPTIMIZATION_HEADER_GUARD
#define GTL_ENGINE_OPTIMIZATION_HEADER_GUARD

#include "gtlCore.h"
#include <eastl/map.h>

namespace GTL
{
	namespace Engine
	{
		namespace Profiling
		{
			struct Function
			{
				struct ProfileLine
				{
					int Line;
					int Count;
					uint64_t HighestTime;
					uint64_t LowestTime;
					uint64_t TotalTime;
					const char* Description;

					ProfileLine() : Line(0), Count(0), HighestTime(0), LowestTime(0), TotalTime(0), Description("") {}
				};

				uint64_t StartTime;
				const char* FuncName;
				const char* FileName;
				int StartLine;
				eastl::map<int,ProfileLine> Lines;

				Function(const char* funcName, const char* fname, int sl) : FuncName(funcName), FileName(fname), StartLine(sl) {  }
				void Reset() { StartTime = Backend->GetTimeMsec(); }
				void Tick(int line, const char* name = "");
				~Function() { Output(); }
				void Output();
			};

#ifdef GTL_DEBUG
#define GTL_PROFFUNC(name) GTL::Engine::Profiling::Function name(__FUNCTION__, __FILE__, __LINE__); name.Reset()
#define GTL_TICKPROF(name) name.Tick(__LINE__)
#else
#define GTL_PROFFUNC(name)
#define GTL_TICKPROF(name)
#endif

		}
	}
}

#endif